// TOWN SCRIPT
//    Town 9: Lighthouse - second floor

// This is the special encounter script for this town.
// The states INIT_STATE, EXIT_STATE, and START_STATE have
// meanings that are described in the documenation. States you write
// yourself should be numbered from 10-100.

// flags:
// 9, 2 = town dead

begintownscript;

variables;

short choice, ii;

body;

beginstate INIT_STATE;
	turn_off_training(1);
break;

beginstate EXIT_STATE;
// Always called when the town is left.
break;

beginstate START_STATE;
	if (get_flag(9, 2) == 0) {
		// maybe create wandering monsters
		ii = get_ran(1, 1, 100);
		if (ii > 98) {
			message_dialog("Some undead rise up through the floor!", "");
			ii = get_ran(1, 1, 4);
			if (ii == 1) {
				place_monster(12, 19, 138, 0);
				place_monster(11, 20, 47, 0);
				place_monster(13, 20, 47, 0);
				place_monster(12, 21, 48, 0);
			}
			else if (ii == 2) {
				place_monster(12, 19, 91, 0);
				place_monster(11, 20, 48, 0);
				place_monster(13, 20, 48, 0);
				place_monster(12, 21, 47, 0);
			}
			else if (ii == 3) {
				place_monster(12, 19, 136, 0);
				place_monster(11, 20, 137, 0);
				place_monster(13, 20, 121, 0);
			}
			else if (ii == 4) {
				place_monster(12, 19, 127, 0);
				place_monster(11, 20, 136, 0);
				place_monster(13, 20, 136, 0);
			}
		}
	}
	if (get_ran(1, 0, 100) < 6) {
		text_bubble_on_char(6, "Thanks for clearing out the undead.");
	}
break;

beginstate 10;
	// stairs up to top level
	move_to_new_town(10, 20, 18);
	block_entry(1);
break;

beginstate 11;
	// stairs down to first level
	move_to_new_town(8, 18, 9);
	block_entry(1);
break;

beginstate 12;
	message_dialog("The shelves contain a selection of charts and maps.", "You thumb through the papers, but find nothing useful.");
break;

beginstate 13;
	if (get_flag(9, 0) == 0) {
		set_flag(9, 0, 1);
		reset_dialog();
		add_dialog_str(0, "As you thumb through the maps and charts on these shelves, you find a strange looking paper.", 0);
		add_dialog_str(1, "It appears to contain writings on ways to become resistant to the elements.", 0);
		add_dialog_str(2, "You study the paper eagerly learning what you can from it.", 0);
		add_dialog_str(3, "Everybody in the group picks up the resistance knowledge.", 0);
		add_dialog_choice(0, "OK");
		choice = run_dialog(1);
		play_sound(60);
		alter_stat(1000, 26, 1);
	}
	else {
		set_state_continue(12);
	}
break;

beginstate 14;
	message_dialog("There are a variety of buttons, switches and lights on the control panel.", "You aren't sure what is what so you back away from the panel.");
break;

beginstate 15;
	if (get_flag(9, 1) == 0) {
		set_flag(9, 1, 1);
		message_dialog("The large box has a plaque which reads _First Aid_", "Inside are a couple of Heal All's.  These might come in handy.");
	}
break;
